<!--
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License. See accompanying LICENSE file.
-->

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="description" content="StreamSets Data Collector">
  <title ng-bind="common.title">StreamSets Data Collector</title>

  <script type="text/javascript">
    var baseHref = document.location.pathname,
      collectorIndex = baseHref.indexOf('/collector/');

    if(collectorIndex !== -1) {
      baseHref = baseHref.substr(0, collectorIndex + 1);
    } else {
      var restIndex = baseHref.indexOf('/rest/');
      if(restIndex !== -1) {
        baseHref = baseHref.substr(0, restIndex + 1);
      }
    }

    document.write("<base href='" + baseHref + "' />");
  </script>

  <link rel="icon" type="image/png" href="assets/favicon.png">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">

  <!-- compiled CSS --><% styles.forEach( function ( file ) { %>
  <link rel="stylesheet" type="text/css" href="<%= file %>" /><% }); %>
</head>
<body>
  <div class="navbar navbar-default navbar-fixed-top" role="navigation">
    <div class="header-container">
      <div class="navbar-header">
        <a class="logo" href="/">
          <img src="assets/logo.png" />
        </a>
      </div>
    </div>
  </div>

  <div class="container login-container">
    <div class="row">
      <div id="loginErrorMessageDivId" class="col-xs-6 col-xs-offset-3 col-sm-5 col-sm-offset-4 col-md-4 col-md-offset-4 col-lg-4 col-lg-offset-4 alert alert-danger" role="alert">
        Log In Failed.
      </div>
    </div>

    <div class="row">
      <div class="col-xs-6 col-xs-offset-3 col-sm-5 col-sm-offset-4 col-md-4 col-md-offset-4 col-lg-4 col-lg-offset-4 form-login">
        <form class="form-horizontal clearfix" action="j_security_check" method="POST">
          <h4>Log In</h4>
          <input type="text" id="usernameId" name="j_username" class="form-control" placeholder="username" autofocus="true"/>
          <input type="password" id="passwordId" name="j_password" class="form-control" placeholder="password" />
          <input type="hidden" id="basePathInputID" name="basePath" class="form-control" value="" />
          <button type="submit" id="loginId" class="btn btn-primary pull-right">Log In <i class="fa fa-sign-in"></i></button>
        </form>
      </div>
    </div>
  </div>

  <script>
    var queryString = window.location.search;
    if(queryString && queryString.indexOf('error=true') !== -1) {
      var errorDiv = document.getElementById('loginErrorMessageDivId');
      errorDiv.style.visibility = 'visible';
    }

    var basePathInput = document.getElementById("basePathInputID");
    if(basePathInput) {
      basePathInput.value = baseHref;
    }
  </script>

</body>
</html>